function formatpostion(_arr){
  let cureenArr=[];
  _arr.map(o=>{
    cureenArr.push(o.split(',')) ;
  });
  return cureenArr
}
module.exports={
  formatTree(arr=[],children='children',title='title',key='key'){
    let tree=(arr)=>{
      arr.map(item=>{
        item['title']=item[title];
        item[`key`]=item[key];
        item[`children`]=item[children];

        if((_.get(item,'children')||[]).length>0){
          tree(item.children);
        }
      })
    }
    tree(arr);
    return arr;
  },
  formatpostion(arr){
    return formatpostion(arr)
  },
  getTreeElm(arr=[],key='key'){
    let elms=[];
    let tree=(arr)=>{
      arr.map(item=>{
        elms.push(item[key]);
        if((_.get(item,'children')||[]).length>0){
          tree(item.children);
        }
      })
    }
    tree(arr);
    return elms;
  },
  fromatMapInfo(arr=[]){//格式化线条路径
    arr.map(item=>{
      let _arr=(JSON.parse(item.position)||[]);
      item.path=formatpostion(_arr);
    })
    return arr
  },
  getClassNamme(item){

    // _.get(item,'offlineStatus')&&classname.push('offlineStatus');
    // _.get(item,'faultStatus')&&classname.push('faultStatus');
    // _.get(item,'abnormalStatus')&&classname.push('abnormalStatus');
    // _.get(item,'normalStatus')&&classname.push('normalStatus');
    switch (_.get(item,'deviceStatus'))  {
      case 2:
        return 'faultStatus';
        break;
      case 3:
        return 'abnormalStatus';
        break;
      case 4:
        return 'offlineStatus';
        break;
      default:
        return 'normalStatus';
    }


  },
  getPoints(arr=[]){//格式化设备落点
    let devicePoints=[];
    arr.map(item=>{
      (_.get(item,'device')||[]).map(o=>{

        devicePoints.push({...o,address:item.address,orgName:item.orgName,hlName:item.name,projectName:item.projectName,className:this.getClassNamme(o),hlId:item.id,gps_lng:(_.get(o,'position')||'').split(',')[0],gps_lat:(_.get(o,'position')||'').split(',')[1]})
      })
    })

    console.log(devicePoints,'devicePoints===')
    return devicePoints;
  },
}